﻿using Supermarket;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace XLSupermarket.Financial.Spending_record
{
    public partial class Spending_recordForm : Form
    {
        public Spending_recordForm()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //商品支出表
            string date1 = this.dateTimePicker1.Value.ToString("yyyy-MM-dd");
            string date2 = this.dateTimePicker2.Value.ToString("yyyy-MM-dd");
            string sql1 = string.Format("select Trade_Name 商品名称,Bar_code 商品条形码,Purchase_price 商品进价,Number 进货数量,Purchase_price*Number 商品总支出,Purchase_time 进货时间,Other 备注 from Goods_Warehousing where Purchase_time > '{0}' and Purchase_time < '{1}'", date1,date2);
            this.dataGridView3.DataSource = DBHelper.FillData(sql1);
            double sum1 = 0;
            DataTable dt1 = (DataTable)this.dataGridView3.DataSource;
            for (int i = 1; i < dataGridView3.RowCount; i++)
            {
                double num = double.Parse(dt1.Rows[i - 1][4].ToString());
                sum1 += num;
            }

            //薪资支出表
            string sql2 = string.Format("select ei.EP_Name 员工姓名,se.Base_Pay 基本薪资,se.Bonus 奖金,se.Commission 提成,se.Base_Pay+se.Bonus+se.Commission 薪资总支出,se.Date_Of_issue 发放日期,se.Other 备注 from EP_Salary se, EP_information ei where se.EP_ID = ei.EP_ID and se.Date_Of_issue > '{0}' and se.Date_Of_issue < '{1}'", date1, date2);
            this.dataGridView1.DataSource = DBHelper.FillData(sql2);
            double sum2 = 0;
            DataTable dt2 = (DataTable)this.dataGridView1.DataSource;
            for (int i = 1; i < dataGridView1.RowCount; i++)
            {
                double num = double.Parse(dt2.Rows[i - 1][4].ToString());
                sum2 += num;
            }

            //总支出表
            double sum3 = sum1 + sum2;
            DataTable dt3 = new DataTable();
            dt3.Columns.Add("商品总支出", Type.GetType("System.String"));
            dt3.Columns.Add("薪资总支出", Type.GetType("System.String"));
            dt3.Columns.Add("总支出", Type.GetType("System.String"));
            dt3.Rows.Add(new Object[] { sum1.ToString(), sum2.ToString(), sum3.ToString() });
            this.dataGridView2.DataSource = dt3;

        }

        private void button3_Click(object sender, EventArgs e)
        {
            ExportToExcel d = new ExportToExcel();
            d.OutputAsExcelFile(dataGridView3);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            ExportToExcel d = new ExportToExcel();
            d.OutputAsExcelFile(dataGridView3);
        }

        private void button4_Click(object sender, EventArgs e)
        {
            ExportToExcel d = new ExportToExcel();
            d.OutputAsExcelFile(dataGridView3);
        }
    }
}
